#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    picID = 2;

     QPixmap pix("E:\\QT_project\\temp\\objectTimer\\picture\\1.png");
     ui->label->setPixmap(pix);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_startButton_clicked()
{
    //开启定时器，返回定时器id
    myTimerId = this->startTimer(TIMEOUT);
}

void Widget::timerEvent(QTimerEvent *event)
{
    if (event->timerId() != myTimerId)
    {
        return;
    }
    QString path("E:\\QT_project\\temp\\objectTimer\\picture\\");
    path += QString::number(picID);
    path += ".png";

    QPixmap pix(path);
    ui->label->setPixmap(pix);

    picID++;
    if(picID == 5)
        picID = 1;
}


void Widget::on_stopButton_clicked()
{
    this->killTimer(myTimerId);
}

